﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using DevExpress.XtraReports.UI;
using ViCode_LeVi.Controls.Logs;
using ViCode_LeVi.Data;
using System.Collections.Specialized;
using ViCode_LeVi.Controls.Charts;

namespace ViCode_LeVi.Controls.Reports
{
    public partial class ChartReport : XtraReport_PotentialPortfolioChart
    {
        private Hashtable m_oCharts;

        public ChartReport(): base()
        {
            this.m_oCharts = new Hashtable();
        }

        public int AddChart(ChartCtrl oChartCtrl)
        {
            int count = 0;
            try
            {
                if (this.m_oCharts != null)
                {
                    this.m_oCharts.Add(this.m_oCharts.Count, oChartCtrl);
                }
                count = this.m_oCharts.Count;
            }
            catch (Exception exception)
            {
                Log.LogException(exception);
            }
            return count;
        }

        public int CreateReport(StringCollection aHiddenElements)
        {
            bool flag = true;
            bool bHasInterpretation = false;
            int riNumberOfElements = 0;
            int num2 = 0;
            try
            {
                ReportTemplate.ShowExportFilters(this);
                ReportTemplate.CustomizeUI(this);
                foreach (ChartCtrl ctrl in this.m_oCharts.Values)
                {
                    flag = true;
                    if (ctrl != null)
                    {
                        if (ctrl is PotentialPortfolioChart)
                        {
                            PotentialPortfolioChartSubReport oChartSubReport = new PotentialPortfolioChartSubReport();
                            PotentialPortfolioChart oChartCtrl = (PotentialPortfolioChart) ctrl;
                            //Todo
                            //oChartSubReport.Interpretation = base.WorkingProject.CurrentPeriod.InterpretationPotentialPortfolio;
                            if (oChartSubReport.CreateReport(oChartCtrl, ref riNumberOfElements))
                            {
                                //Todo
                                bHasInterpretation = true;// ReportTemplate.StringHasValue(base.WorkingProject.CurrentPeriod.InterpretationPotentialPortfolio);
                                if (base.AddNewSubReport(oChartSubReport, riNumberOfElements, bHasInterpretation) > 0)
                                {
                                    num2++;
                                }
                                else
                                {
                                    aHiddenElements.Add(ReportTemplate.s_sPotentialPortfolioChart);
                                }
                            }
                        }
                        else if (ctrl is BarChartImportance)
                        {
                            BarChartImportanceSubReport report2 = new BarChartImportanceSubReport();
                            BarChartImportance importance = (BarChartImportance) ctrl;
                            //todo
                            report2.Interpretation = string.Empty;// base.WorkingProject.CurrentPeriod.InterpretationImportanceChart;
                            if (report2.CreateReport(importance, ref riNumberOfElements))
                            {
                                //todo
                                bHasInterpretation = true;// ReportTemplate.StringHasValue(base.WorkingProject.CurrentPeriod.InterpretationImportanceChart);
                                if (base.AddNewSubReport(report2, riNumberOfElements, bHasInterpretation) > 0)
                                {
                                    num2++;
                                }
                                else
                                {
                                    aHiddenElements.Add(ReportTemplate.s_sBarChartImportance);
                                }
                            }
                        }
                        else if (ctrl is BarChartQQS)
                        {
                            BarChartQQS tqqs = (BarChartQQS)ctrl;
                            BarChartQQSSubReport report3 = new BarChartQQSSubReport
                            {
                                EFType = FactorType.BK
                            };
                            if (report3.CreateReport(tqqs, ref riNumberOfElements))
                            {
                                //todo
                                bHasInterpretation = true;// ReportTemplate.StringHasValue(base.WorkingProject.CurrentPeriod.InterpretationQQSBarChartBK);
                                if (base.AddNewSubReport(report3, riNumberOfElements, bHasInterpretation) > 0)
                                {
                                    num2++;
                                }
                                else
                                {
                                    aHiddenElements.Add(ReportTemplate.s_sBarChartQQS + " (BK)");
                                }
                            }
                            BarChartQQSSubReport report4 = new BarChartQQSSubReport
                            {
                                EFType = FactorType.SK
                            };
                            if (report4.CreateReport(tqqs, ref riNumberOfElements))
                            {
                                //todo
                                bHasInterpretation = true;//ReportTemplate.StringHasValue(base.WorkingProject.CurrentPeriod.InterpretationQQSBarChartSK);
                                if (base.AddNewSubReport(report4, riNumberOfElements, bHasInterpretation) > 0)
                                {
                                    num2++;
                                }
                                else
                                {
                                    aHiddenElements.Add(ReportTemplate.s_sBarChartQQS + " (SK)");
                                }
                            }
                            BarChartQQSSubReport report5 = new BarChartQQSSubReport
                            {
                                EFType = FactorType.HK
                            };
                            if (report5.CreateReport(tqqs, ref riNumberOfElements))
                            {
                                //todo
                                bHasInterpretation = true;// ReportTemplate.StringHasValue(base.WorkingProject.CurrentPeriod.InterpretationQQSBarChartHK);
                                if (base.AddNewSubReport(report5, riNumberOfElements, bHasInterpretation) > 0)
                                {
                                    num2++;
                                }
                                else
                                {
                                    aHiddenElements.Add(ReportTemplate.s_sBarChartQQS + " (HK)");
                                }
                            }
                        }
                        else
                        {
                            flag = false;
                            num2 = 0;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                num2 = 0;                
                Log.LogException(exception);
            }
            return num2;
        }
    }
}
